package com.wtp;

import android.app.AlertDialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

public class OrderListAdapter extends BaseAdapter {
	
	private Context mContext;
	private int mIndex = 0;
	private int mCount;
	private int[] colors = {R.color.order_item_color_sh,R.color.order_item_color_sp,R.color.order_item_color_qf};
	private String[] jd_name = {"审核","签发","会签"};
	private int mOd;
	
	public OrderListAdapter(Context context,int index,int count,int od) {
		this.mContext = context;
		this.mIndex = index;
		this.mCount = count;
		this.mOd = od;
	}
	

	@Override
	public int getCount() {
		return mCount;
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = LayoutInflater.from(mContext).inflate(R.layout.gd_list_item, null);
			viewHolder.recell = (Button) convertView.findViewById(R.id.zh);
			viewHolder.jd = (TextView) convertView.findViewById(R.id.jd);
			convertView.setTag(viewHolder);
		}else{
			viewHolder = (ViewHolder) convertView.getTag();
		}
		if (mIndex == 1) {
			viewHolder.recell.setVisibility(View.GONE);
		}else if (mIndex == 2) {
			viewHolder.recell.setVisibility(View.VISIBLE);
		}
		
		for (int i = 0; i < mCount; i++) {
			if (i == position) {
				if (mOd == 2) {
					viewHolder.jd.setBackgroundColor(mContext.getResources().getColor(R.color.order_item_color_gd));
					viewHolder.jd.setText("归档");
				}else{
					viewHolder.jd.setBackgroundColor(mContext.getResources().getColor(colors[i]));
					viewHolder.jd.setText(jd_name[i]);
				}
			}
		}
		
		viewHolder.recell.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				new AlertDialog.Builder(mContext).setTitle("提示").setMessage("确认召回此工单").setPositiveButton("召回", null).setNegativeButton("取消", null).show();
			}
		});
		return convertView;
	}
	
	class ViewHolder{
		Button recell;
		TextView jd;
	}
}
